package info.zhoutian.blog.controller;

import info.zhoutian.blog.domain.Girl;
import info.zhoutian.blog.repository.GirlRepository;
import info.zhoutian.blog.service.GirlService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * Created by Administrator on 2018/8/24.
 */
@RestController
public class GirlController {

    @Autowired
    private GirlService girlService;


//    @GetMapping(value = "/girls")
//    public List<Girl> getList(){
//
//        return girlRepository.findAll();
//    }


    @Transactional
    @GetMapping(value = "/addGirl")
    public Girl addGirl(@Valid Girl girl, BindingResult bindingResult){
        if(bindingResult.hasErrors()){
            System.out.println(bindingResult.getFieldError().getDefaultMessage());
            return null;
        }

        Girl g = new Girl();
        g.setCupSize(girl.getCupSize());
        g.setAge(girl.getAge());

        return girlService.addGirl(g);
    }
}
